package mspbots.data.manage.core;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import javax.validation.Valid;
import java.util.Map;

/**
 * mspbots.data.manage.core.AppController
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/10/22
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("client/{tenantId}")
public class AppController {

    private final AppServiceImpl appService;

    @GetMapping("get")
    public Flux<JsonNode> get(@PathVariable Long tenantId, @RequestParam Map<String, Object> queryParams) {
        Assert.notNull(queryParams.get("client"), "Query params [client] cannot be empty.");
        Assert.notNull(queryParams.get("path"), "Query params [path] cannot be empty.");
        return this.appService.get(tenantId, queryParams);
    }

    @PostMapping("post")
    public Flux<JsonNode> post(@PathVariable Long tenantId, @Valid @RequestBody QueryBody queryBody) {
        return this.appService.post(tenantId, queryBody);
    }
}
